<!--
 * @Description: 加钟设置
 * @Author: DXV-RGWU-TUFH-RFCY-IEGMYY
 * @Date: 2023-02-20 09:51:55
 * @LastEditTime: 2023-08-01 16:41:20
 * @LastEditors: DXV-RGWU-TUFH-RFCY-IEGMYY
-->

<template>
  <div class="lb-service-bell-set">
    <top-nav></top-nav>
    <div class="page-main">
      <el-form
        @submit.native.prevent
        :model="subForm"
        :rules="subFormRules"
        ref="subForm"
        label-width="150px"
        class="config-form"
      >
        <el-form-item label="选择计算规则" prop="material_type">
          <el-radio-group v-model="subForm.material_type">
            <el-radio :label="0">规则一</el-radio>
            <el-radio :label="1">规则二</el-radio>
            <lb-tool-tips :padding="0">
              例如：一项289元的服务，包含了9元物料费，{{
                $t('action.attendantName')
              }}百分比为60%
              <div class="mt-md">
                选择规则一：{{
                  $t('action.attendantName')
                }}的提成是扣除了物料费后才按照百分比提成
              </div>
              <div class="mt-sm" style="margin-left: 60px">
                = (服务费 - 物料费) * {{ $t('action.attendantName') }}百分比
              </div>
              <div class="mt-sm" style="margin-left: 60px">
                = (289 - 9) * 60%
              </div>
              <div class="mt-sm" style="margin-left: 60px">= 168元</div>
              <div class="mt-md">
                选择规则二：{{ $t('action.attendantName') }}先提成后减去物料费
              </div>
              <div class="mt-sm" style="margin-left: 60px">
                = 服务费*{{ $t('action.attendantName') }}百分比 - 物料费
              </div>
              <div class="mt-sm" style="margin-left: 60px">= 289 * 60% - 9</div>
              <div class="mt-sm" style="margin-left: 60px">= 164.4元</div>
            </lb-tool-tips>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <lb-button type="primary" @click="submitFormInfo" v-preventReClick>{{
            $t('action.submit')
          }}</lb-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      subForm: {
        material_type: 0
      },
      subFormRules: {
        material_type: { required: true, type: 'number', message: '请选择', trigger: 'blur' }
      }
    }
  },
  created () {
    this.getFormInfo()
  },
  computed: {
    ...mapState({
      routesItem: state => state.routes
    })
  },
  methods: {
    async getFormInfo () {
      let { code, data } = await this.$api.system.configInfo()
      if (code !== 200) return
      for (let i in this.subForm) {
        this.subForm[i] = data[i]
      }
    },
    async submitFormInfo () {
      let flag = false
      this.$refs['subForm'].validate(valid => {
        if (valid) {
          flag = true
        }
      })
      let subForm = JSON.parse(JSON.stringify(this.subForm))
      if (flag) {
        await this.$api.system.configUpdate(subForm)
        this.$message.success(this.$t('tips.successSub'))
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-service-bell-set {
  width: 100%;
  .config-form {
    .el-input,
    .el-input-number {
      width: 300px;
    }
  }
}
</style>
